<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once(dirname(__FILE__) . "/../../dbcom/StaisCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/OrderCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/ReservetimeCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/RagionCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/AppointCom.php");
require_once(dirname(__FILE__) . "/../../common/Common.php");
require_once(dirname(__FILE__) . "/../../dbcom/UserCom.php");

$staiscom = new StaisCom();
$ordercom = new OrderCom();
$reservetimecom = new ReservetimeCom();
$ragioncom = new RagionCom();
$appointcom = new AppointCom();
$usercom = new UserCom();
$common = new Common();

$userid = $common->getLogin();
if (!isset($userid) || empty($userid)) {
    header('Location:./../login.php');
}

$user = $usercom->getUserById($userid);

//年龄统计
if ($user['role'] == 0) {
    $agearr = $appointcom->getNumByAge();
} else {
    $agearr = $appointcom->getNumwByAge($user['community_id']);
}
$age = array("legend" => "[", "data" => "");
if (!empty($agearr)) {
    foreach ($agearr as $k1 => $v1) {
        $age["legend"] .= '"' . $v1["age"] . '岁",';
        $age["data"] .= "{value: " . $v1['count(1)'] . ", name: '" . $v1["age"] . "岁" . "'},";
    }
}
$age["legend"] .= "]";
//楼层统计
if ($user['role'] == 0) {
    $floorarr = $appointcom->getNumByFloor();
} else {
    $floorarr = $appointcom->getNumwByFloor($user['community_id']);
}
$floor = array("legend" => "[", "data" => "");
if (!empty($floorarr)) {
    foreach ($floorarr as $k2 => $v2) {
        $floor["legend"] .= '"' . $v2["floor"] . '层",';
        $floor["data"] .= "{value: " . $v2['count(1)'] . ", name: '" . $v2["floor"] . "层" . "'},";
    }
}
$floor["legend"] .= "]";
//时间段比例
$reservetimearr = $appointcom->getNumByRtime();
$rtime = array("legend" => "[", "data" => "");
if (!empty($reservetimearr)) {
    foreach ($reservetimearr as $k3 => $v3) {
        $rtimeinfo = $reservetimecom->getRtimeById($v3['reservetime_id']);
        $rtime["legend"] .= '"' . $rtimeinfo['info'] . '",';
        $rtime["data"] .= "{value: " . $v3['count(1)'] . ", name: '" . $rtimeinfo['info'] . "'},";
    }
}
$rtime["legend"] .= "]";
//性别比例
if ($user['role'] == 0) {
    $sexarr = $appointcom->getNumBySex();
} else {
    $sexarr = $appointcom->getNumwBySex($user['community_id']);
}
$sex = array("legend" => "[", "data" => "");
if (!empty($sexarr)) {
    foreach ($sexarr as $k4 => $v4) {
        if ($v4['sex'] == 1) {
            $sex["legend"] .= '"男",';
            $sex["data"] .= "{value: " . $v4['count(1)'] . ", name: '男'},";
        } else {
            $sex["legend"] .= '"女",';
            $sex["data"] .= "{value: " . $v4['count(1)'] . ", name: '女'},";
        }
    }
}
$sex['legend'] .= "]";
//使用区域和次数
$arealist = $ragioncom->getRagionByType(0);
$areanum = array("legend" => "[", "data" => "[");
if (!empty($arealist)) {
    foreach ($arealist as $k5 => $v5) {
        $num = $appointcom->getNumByArea($v5['id']);
        $areanum['legend'] .= "'" . $v5['name'] . "',";
        $areanum["data"] .= $num . ",";
    }
}
$areanum['legend'] .= "]";
$areanum['data'] .= "]";
//使用区域占比
$area = array("legend" => "[", "data" => "");
if (!empty($arealist)) {
    foreach ($arealist as $k6 => $v6) {
        $num = $appointcom->getNumByArea($v6['id']);
        $area['legend'] .= "'" . $v6['name'] . "',";
        $area["data"] .= "{value: " . $num . ", name: '" . $v6['name'] . "'},";
    }
}
$area['legend'] .= "]";
//低保人群比例
if ($user['role'] == 0) {
    $poornum = $appointcom->getNumByUsertype(4);
    $num = $appointcom->getAllNum();
} else {
    $poornum = $appointcom->getNumwByUsertype(4,$user['community_id']);
    $num = $appointcom->getAllwNum($user['community_id']);
}
$otheruser = $num - $poornum;
$poor = array(
    "legend" => "['低保人数','其他人数']",
    "data" => "{value:" . $poornum . ",name:'低保人数'},{value:" . $otheruser . ",name:'其他人数'}"
);
?>

<!DOCTYPE html>
<html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="keywords" content="">
        <meta name="description" content="">
        <link href="../public/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="../public/css/font-awesome.css?v=4.4.0" rel="stylesheet">

        <link href="../public/css/animate.css" rel="stylesheet">
        <link href="../public/css/style.css?v=4.1.0" rel="stylesheet">

        <link href="../public/css/paging.css" rel="stylesheet">
        <link href="../public/css/showproject.css" rel="stylesheet">
    </head>

    <body class="gray-bg">

        <div class="wrapper wrapper-content animated fadeInUp">
            <div class="row">
                <div class="col-sm-12">

                    <div class="ibox">
                        <div class="ibox-title">
                            <h5>基础统计</h5>
                            <div class="ibox-tools">

                            </div>
                        </div>
                        <div class="ibox-content">
                            <div class="row m-b-sm m-t-sm">
                                <div class="col-md-1">

                                </div>
                                <div class="col-md-11">
                                    <div class="input-group">

                                    </div>
                                </div>
                            </div>

                            <div class="project-list">
                                <div style="height:1300px;">
                                    <!--                                内容-->
                                    <div id="age" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="floor" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="reservetime" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="sex" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="areanum" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="area" style="width: 350px;height:400px;float:left;"></div>
                                    <div id="poor" style="width: 350px;height:400px;float:left;"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>




        <!-- 全局js -->
        <script src="../public/js/jquery.min.js?v=2.1.4"></script>
        <script src="../public/js/bootstrap.min.js?v=3.3.6"></script>
        <script src="../public/js/plugins/layer/layer.min.js"></script>
        <script src="../public/js/echarts.js"></script>

        <!-- 自定义js -->
        <script src="../public/js/paging.js?v=1.0.0"></script>
        <script src="../public/js/upload.js?v=1.0.0"></script>
        <script src="../public/js/common.js?v=1.0.0"></script>

        <script>
            $(document).ready(function () {

                $('#loading-example-btn').click(function () {
                    btn = $(this);
                    simpleLoad(btn, true)

                    // Ajax example
                    //                $.ajax().always(function () {
                    //                    simpleLoad($(this), false)
                    //                });

                    simpleLoad(btn, false)
                });
            });
            function simpleLoad(btn, state) {
                if (state) {
                    btn.children().addClass('fa-spin');
                    btn.contents().last().replaceWith(" Loading");
                } else {
                    setTimeout(function () {
                        btn.children().removeClass('fa-spin');
                        btn.contents().last().replaceWith(" Refresh");
                    }, 2000);
                }
            }
            var myChart1 = echarts.init(document.getElementById("age"));
            option = {
                title: {
                    text: '年龄比例',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $age['legend'] ?>
                },
                series: [
                    {
                        name: '年龄统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $age['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart1.setOption(option);
            var myChart2 = echarts.init(document.getElementById("floor"));
            option2 = {
                title: {
                    text: '楼层比例',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $floor['legend'] ?>
                },
                series: [
                    {
                        name: '楼层统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $floor['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart2.setOption(option2);
            var myChart3 = echarts.init(document.getElementById("reservetime"));
            option3 = {
                title: {
                    text: '时间段比例',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $rtime['legend'] ?>
                },
                series: [
                    {
                        name: '时间段统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $rtime['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart3.setOption(option3);
            var myChart4 = echarts.init(document.getElementById("sex"));
            option4 = {
                title: {
                    text: '性别比例',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $sex['legend'] ?>
                },
                series: [
                    {
                        name: '性别统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $sex['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart4.setOption(option4);
            var myChart5 = echarts.init(document.getElementById("areanum"));
            option5 = {
                title: {
                    text: '使用区域和次数',
                    subtext: '',
                    left: 'center'
                },
                xAxis: {
                    type: 'category',
                    data: <?= $areanum['legend'] ?>
                },
                yAxis: {
                    type: 'value'
                },
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                        type : 'line'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                series: [{
                        name: '次数',
                        data: <?= $areanum['data'] ?>,
                        type: 'bar'
                    }]
            };
            myChart5.setOption(option5);
            var myChart6 = echarts.init(document.getElementById("area"));
            option6 = {
                title: {
                    text: '使用区域比例',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $area['legend'] ?>
                },
                series: [
                    {
                        name: '区域统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $area['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart6.setOption(option6);
            var myChart7 = echarts.init(document.getElementById("poor"));
            option7 = {
                title: {
                    text: '低保人群占比',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: <?= $poor['legend'] ?>
                },
                series: [
                    {
                        name: '低保统计',
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [<?= $poor['data'] ?>],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart7.setOption(option7);
        </script>

    </body>
</html>